package com.llkj.qingnianguoxue.adapter;

import android.support.v4.content.ContextCompat;
import android.text.SpannableString;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.bean.CircleListBean;
import com.llkj.qingnianguoxue.util.ClickViewCallback;
import com.llkj.qingnianguoxue.util.ImageLoadingUtil;
import com.llkj.qingnianguoxue.util.TextViewUtil;

import java.util.List;

/**
 * 圈子——兴趣圈子
 */
public class InterestCircleAdapter extends BaseQuickAdapter<CircleListBean.CircleBean, BaseViewHolder> {
    private ClickViewCallback clickViewCallback;
    private int type = 1;//1兴趣，2我的,3搜索

    public InterestCircleAdapter(int layoutResId, List<CircleListBean.CircleBean> data, ClickViewCallback listener) {
        super(layoutResId, data);
        clickViewCallback = listener;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, CircleListBean.CircleBean item) {
        ImageLoadingUtil.loadingCircleBorderImgCenterCrop((ImageView) baseViewHolder.getView(R.id.iv_head), item.getImg(), R.color.transparent);
        baseViewHolder.setText(R.id.tv_name, item.getName());
        baseViewHolder.setText(R.id.tv_introduction, item.getFans()+"人气");

        String price = "￥"+item.getPrice()+"元/"+item.getCycle()+"天";
        SpannableString spannableString = TextViewUtil.getForegroundColorSpan(mContext,price,0,price.length()-4, ContextCompat.getColor(mContext, R.color.colorFE4A49));
        baseViewHolder.setText(R.id.tv_price,spannableString);

        TextView tvAddCircle = baseViewHolder.getView(R.id.tv_add_circle);
        ImageView ivGo = baseViewHolder.getView(R.id.tv_circle_right);
        if (type == 1) {//未加入
            if("1".equals(item.getIs_add())){//已加入
                ivGo.setVisibility(View.GONE);
                tvAddCircle.setVisibility(View.VISIBLE);
                tvAddCircle.setText("√已加入");
                tvAddCircle.setSelected(true);
            }else{//未加入
                ivGo.setVisibility(View.GONE);
                tvAddCircle.setVisibility(View.VISIBLE);
                tvAddCircle.setText("+加入");
                tvAddCircle.setSelected(false);
                baseViewHolder.addOnClickListener(R.id.tv_add_circle);
            }
        } else if (type == 2) {//已加入
            ivGo.setVisibility(View.VISIBLE);
            tvAddCircle.setVisibility(View.GONE);
        } else if (type == 3) {
            if("1".equals(item.getIs_add())){//已加入
                ivGo.setVisibility(View.VISIBLE);
                tvAddCircle.setVisibility(View.GONE);
            }else{//未加入
                ivGo.setVisibility(View.GONE);
                tvAddCircle.setVisibility(View.VISIBLE);
                tvAddCircle.setText("+加入");
                tvAddCircle.setSelected(false);
                baseViewHolder.addOnClickListener(R.id.tv_add_circle);
            }
        }

    }

    /**
     * 设置界面显示UI
     *
     * @param type1 1兴趣，2我的
     */
    public void setType(int type1) {
        type = type1;
    }
}
